// TunnelRace.cpp : Defines the entry point for the console application.
//

#include <string>

#include "CommonHeaders.h"

#include <stdio.h>

#include "Core.h"
#include "ErrorHandler.h"

void onDisplay(void)
{
	Core::Instance()->Render();
}

void onIdle(void)
{
	Core::Instance()->Animate();
}

void onKeyboard(unsigned char key, int x, int y) 
{
	glutPostRedisplay();
}

void onMouse(int button, int state, int x, int y) 
{
	// A GLUT_LEFT_BUTTON / GLUT_RIGHT_BUTTON
	// ill. a GLUT_DOWN / GLUT_UP makrokat hasznald.
}

void onInitialization()
{
	//Initialize GLEW 
	GLenum glewError = glewInit(); 
	if( glewError != GLEW_OK ) 
	{ 
		ErrorHandler::Instance()->Fatal( "Error initializing GLEW!\n") ; //, glewGetErrorString( glewError ) ); 		
	} 
	
	//Make sure OpenGL 2.1 is supported 
	if( !GLEW_VERSION_2_1 ) 
	{ 
		ErrorHandler::Instance()->Fatal( "OpenGL 2.1 not supported!\n" ); 
	}

	Core::Instance()->Init();
}

int main(int argc, char** argv)
{
	// init GLUT and create Window
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowPosition(100,100);
	glutInitWindowSize(320,320);

	glutCreateWindow("TunnelRace");

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	onInitialization();

	// register callbacks
	glutDisplayFunc(onDisplay);
	glutMouseFunc(onMouse); 
	glutIdleFunc(onIdle);
	glutKeyboardFunc(onKeyboard);
	
	// enter GLUT event processing cycle
	glutMainLoop();

	return 0;
}